<template>
  <div class="region">
    <div class="content">
      <div class="left">地区:</div>
      <ul>
        <li :class="{active:regionvalue==''}" @click="changeRegion('')">全部</li>
        <li v-for="(region,index) in regionArr" :key="region.id" :class="region.value==regionvalue?'active':''" @click="changeRegion(region.value)">{{region.name}}</li>
      </ul>
    </div>
  </div>
</template>

<script setup lang="ts">
  import {ref,onMounted} from 'vue'
import {reqHospitalLevelAndRegion} from '@/api/home/index'
import type {HospitalLevelAndRegion,HospitalLevelAndRegionResponseData} from '@/api/home/type'
let regionArr = ref<HospitalLevelAndRegion[]>([])
let regionvalue = ref<string>('')
  onMounted(()=>{
    getHospitalRegion()
  })
// 获取医院等级与地区信息
const getHospitalRegion = async ()=>{
  let res:HospitalLevelAndRegionResponseData = await reqHospitalLevelAndRegion("Beijin")
  if(res.code==200){
    regionArr.value = res.data
  }
}
const changeRegion = (level:string)=>{
  regionvalue.value = level
  $emit('getRegion',level)
}
let $emit = defineEmits(['getRegion'])
</script>

<style scoped lang="scss">
.region {
  color: #7f7f7f;
  margin-top: 20px;
  .content {
    display: flex;
    .left {
      margin-right: 10px;
      width: 50px;
    }
    ul {
      display: flex;
      flex-wrap: wrap;
      li {
        margin-right: 10px;
        margin-bottom: 10px;
        &.active {
          color: #55a6fe;
        }
      }
      li:hover {
        color: #55a6fe;
      }
    }
  }
}
</style>
